package com.book.service.impl;

import com.book.api.RankingApi;
import com.book.pojo.MonthlyPass;
import com.book.mapper.MonthlyPassDao;
import com.book.pojo.MonthlyRanking;
import com.book.service.MonthlyPassService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author fk
 * @since 2023-10-14 09:16:53
 */
@Service
public class MonthlyPassServiceImpl extends ServiceImpl<MonthlyPassDao, MonthlyPass> implements MonthlyPassService {

    @Autowired
    private MonthlyPassDao monthlyPassDao;
    @Autowired
    private RankingApi collectRankingApi;

    @Override
    public void addMonthlyPass(MonthlyPass monthlyPass) {
        monthlyPassDao.insert(monthlyPass);
        Long bookId = monthlyPass.getBookId();
        collectRankingApi.monthlydeleteBybid(bookId);
        MonthlyPass m =monthlyPassDao.monthlyRankingByBookId(bookId);
        MonthlyRanking ranking = new MonthlyRanking();
        ranking.setMonthlySum(m.getMonthlySum());
        ranking.setBookId(m.getBookId());
        collectRankingApi.addMonthlyRanking(ranking);



    }

    @Override
    public List<MonthlyPass> monthlyRanking() {
        return monthlyPassDao.monthlyRanking();
    }

    @Override
    public void addByPass(MonthlyPass monthlyPass) {
        monthlyPassDao.insert(monthlyPass);
    }
}
